﻿using CommunityToolkit.Mvvm.ComponentModel;
using GameView.Comment;
using System.ComponentModel.DataAnnotations;

public partial class RechargeQueryDto : ObservableValidator, IValidatableObject
{
    /// <summary>
    /// 当前页
    /// </summary>
    public int PageIndex { get; set; } = 1;

    /// <summary>
    /// 每页行数
    /// </summary>
    public int PageSize { get; set; } = 20;

    public int RechargeOrderStatus { get; set; }

    /// <summary>
    /// 项目名称
    /// </summary>
    public string ProjectName { get; set; }

    /// <summary>
    /// 游戏名称
    /// </summary>
    public string GameName { get; set; }

    /// <summary>
    /// 角色名称
    /// </summary>
    public string CharacterName { get; set; }

    /// <summary>
    /// 发货人
    /// </summary>
    public string Merchant { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    public string StartTime => StartTimeDT.ReBuildTIme(StartTime24);

    /// <summary>
    /// 结束时间
    /// </summary>
    public string EndTime => EndTimeDT.ReBuildTIme(EndTime24);

    /// <summary>
    /// 开始时间
    /// </summary>
    [ObservableProperty]
    [Required]
    [NotifyPropertyChangedFor(nameof(StartTime))]
    private string _startTimeDT = DateTime.Now.ToStringFormatShort();

    /// <summary>
    /// 结束时间
    /// </summary>
    [ObservableProperty]
    [Required]
    [NotifyPropertyChangedFor(nameof(EndTime))]
    private string _endTimeDT = DateTime.Now.ToStringFormatShort();

    /// <summary>
    /// 开始时间
    /// </summary>
    [ObservableProperty]
    [Required]
    [NotifyPropertyChangedFor(nameof(StartTime))]
    private string _startTime24 = "00:00";

    /// <summary>
    /// 结束时间
    /// </summary>
    [ObservableProperty]
    [Required]
    [NotifyPropertyChangedFor(nameof(EndTime))]
    private string _endTime24 = "23:59";

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        var s = StartTime.TryConvertToDateTime();
        var e = EndTime.TryConvertToDateTime();

        if (s.HasValue && e.HasValue && e < s)
        {
            yield return new ValidationResult("结束时间不能早于开始时间", [nameof(EndTime)]);
        }
    }
}